package com.zoweunion.mechanic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zoweunion.mechanic.entity.DeptEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zoweunion.mechanic.dao.RoleUserDao;
import com.zoweunion.mechanic.entity.RoleUserEntity;
import com.zoweunion.mechanic.service.RoleUserService;


@Service("roleUserService")
public class RoleUserServiceImpl extends ServiceImpl<RoleUserDao, RoleUserEntity> implements RoleUserService {

    @Autowired
    private RoleUserDao roleUserDao;


    @Override
    public PageInfo queryPage(Map<String, Object> map)  {
        Integer pageSize = Integer.valueOf(map.get("pageSize").toString());
        Integer currentPage = Integer.valueOf(map.get("currentPage").toString());
        PageHelper.startPage(currentPage, pageSize);
        List<RoleUserEntity> mapList = roleUserDao.queryPage(map);
        PageInfo<RoleUserEntity> mapPageInfo = new PageInfo<>(mapList);
        return mapPageInfo;
    }

    @Override
    public List<RoleUserEntity> roleUserListTree(Map<String, Object> params) {
            List<RoleUserEntity> departments =roleUserDao.roleUserListTree(params);
            if (departments.size()>0){
                DeptEntity department1=new DeptEntity();
                for (int i = 0; i <departments.size() ; i++) {
                    Long id = departments.get(i).getId();
                    department1.setPId(id);
                    Map<String, Object> hashMap = new HashMap<>();
                    hashMap.put("pid", id);
                    List<RoleUserEntity> childList=roleUserListTree(hashMap);
                    departments.get(i).setChildList(childList);
                }
        }
        return departments;
    }

}